import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-07-23
 * Time: 16:29
 */
public class Demo1 {
    public static void main(String[] args) {
        MyBlockingQueue blockingQueue = new MyBlockingQueue(1000);
        Thread t1 = new Thread(() -> {
            int i = 1 ;
            while(true) {
                try {
                    blockingQueue.put(" " + i);
                    System.out.println("put: " + i);
                    i++;
                    //Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        Thread t2 = new Thread(() -> {
            while(true) {
                try {
                    Thread.sleep(1000);
                    String i = blockingQueue.take();
                    System.out.println("take: " + i);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t1.start();
        t2.start();
    }
}
